/*
function MaxiWindow(){ //窗口最大化
    var str = '<object id=maxiw type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"><param name="Command" value="MAXIMIZE"></object>';
    if (document.body) {
        if (!document.getElementById("maxiw")) 
            document.body.insertAdjacentHTML("BeforeEnd", str);
        maxiw.Click();
    }
}
*/

//当前座席的状态
CURRENT_STATUS_CODE = '';


                  
/**
 * 就绪的时候需要做的
 */
function onAvaiable() {
	            CALL_DATA = {
                calledNum: '',
                callerNum: '',
                inlineFlag: '',
                callId: '',
                callDirection: '',
                callIntime: '',
                vipCode: '',
                vipType: '',
                callType: '',
				recordFileName:'',
				seqNumber:'',
				recordId:''
            };
			
			//前台进线客户清空
			CUURENT_INLINE_CUSTOMER = null;
			
			//清空逻辑callid
			LOGIC_CALL_ID = '';
			
			//清空session,后台进线客户
			 Ext.Ajax.request({
                url: '../ib/pages/inline/ibInline!clearInlineClient.action',
                success: function(result, obj){
                    var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                    if (jsonFromServer.success) {
						//alert('clear success');
                    }
                    else {
                        logDebug("清空session失败");
                    }
                },
                failure: function(){
                	logDebug("清空session出现异常");
                },
                headers: {
                    'my-header': 'foo'
                }
            });
			
			//清空左边客户资料
			
			//表示没有进线客户
			HAS_INLINE_USER = false;
			
			var fpanel = Ext.getCmp('u_custInfo_panel');
			//alert(fpanel);
			if(fpanel!=null){
				fpanel.getForm().reset();
			}
			
            var nameArray = new Array();
            nameArray = [{
                name: 'IB_inline_CUST_CATALOG'
            }, {
                name: 'IB_inline_custCname'
            }, {
                name: 'IB_inline_CUST_ORGAN'
            }, {
                name: 'IB_inline_custCarId'
            }, {
                name: 'IB_inline_custBirthday'
            }, {
                name: 'IB_inline_HOME_NUMBER'
            }, {
                name: 'IB_inline_OFFICE_NUMBER'
            }, {
                name: 'IB_inline_MOBILE_NUMBER'
            }];
            Ext.IbInlineList.setFormDisabled(false, nameArray);
			
            try {
                //设置记录按钮可以不编辑
                Ext.getCmp('d07bcc26-22ca-4b06-b73d-1c1556f0d609').setDisabled(true);
            } 
            catch (e) {
            
            }
/*
            try {
                //设置重置按钮不可以编辑
                Ext.getCmp('392eceed-2ea7-4596-8cd7-c019ddc2155e').setDisabled(true);
            } 
            catch (e) {
            
            }
*/
            
            
            try {
                //设置详情按钮可以编辑
                Ext.getCmp('0fc376b6-926a-45ce-b3e9-9e2da63600aa').setDisabled(true);
            } 
            catch (e) {
            
            }
            
            
            try {
                //设置新增按钮可以编辑
                Ext.getCmp('28430962-f5c5-426d-902c-68120271b531').setDisabled(false);
            } 
            catch (e) {
            
            }
            
            
            try {
                //设置刷选按钮可以编辑
                Ext.getCmp('32f9b19c-218d-4990-aa5d-e824a5293cfe').setDisabled(false);
            } 
            catch (e) {
            
            }


			//激活客户资料面板
			//Ext.IbInlineList.activeCustTabs();
			//就绪的时候更新来电号码显示
			Ext.SoftPhoneAction.setActInfo('Called_info', '');
			
			//最小化窗口然后最大化清除内存
			//MiniWindow();
			
			//refreshIframe();
			
			//for round
			isOpenlockMore=null;
			
//			try {
//				// 重置工单记grid
//				Ext.custInfo_ws.reloadWorkerRecordGridPanel();
//			} catch (e) {
//				
//			}

			//for better 维护工单没有保存
			WORKERRECORD_GLOBAL_ISAVEDATA = false;
			//for better 是否转办单
			HASWORKERRECORD="";
			
			//关闭話務小結inbound与進線客戶資料
			tabs.items.each(function(thisItem, thisindex,
					thisLength) {
				//关闭話務小結inbound与進線客戶資料
				//新增进线用户、話務小結(inbound)、进线客户资料、CS-inbound、进线客户详细资料
				if (thisItem.initialConfig.id == "add_inline_customer_info"||thisItem.initialConfig.id=='428eaca2-5894-4145-8a13-f9af546d1b0f'
				||thisItem.initialConfig.id == "eecdebc6-544a-4a6d-a7be-c25fa6a2df82"||thisItem.initialConfig.id=='a26958c6-7f7a-4a19-85fd-d14390f841f5_Inbound'
				||thisItem.initialConfig.id == 'edit_inline_customer_info_notvip_panel'||thisItem.initialConfig.id == 'edit_inline_customer_info_notvip_parent') {
					tabs.remove(thisItem, true);
				}
			})
			//重置工作台客户资料
			var custInfo_reset = Ext.getCmp('392eceed-2ea7-4596-8cd7-c019ddc2155e');
            if (custInfo_reset != null){
                custInfo_reset.handler();
            }
            var custmess_reload = Ext.getCmp('cusmess_resultTree_reload_id');
            if (custmess_reload != null){
                custmess_reload.handler();
            }
}

/**
 * 专门处理状态改变的Api
 */
Ext.statusChange = function(){
    return {
        init: function(){
            alert('Ext.statusChange');
        },
		/**
		 * 改变当前状态
		 * @param {Object} newstatus	新状态
		 * newstatus = {
		 * 		url:'',状态图片地址
		 * 		name:'',状态名称
		 * 		sid:'',状态ID
		 * 		alertTime:''告警时间
		 *		}
		 */
        change: function(newstatus){
            var newSrc = newstatus.url;
            var newName = newstatus.name;
            var newStatusId = newstatus.sid;
			var newCallStatus = newstatus.callStatus;
			//alert("下一状态："+newStatusId+":"+newCallStatus+":"+newName);
			//告警时间
			var newAlertTime = newstatus.newAlertTime;
			//alert("newCallStatus is:::::"+newCallStatus);
			Ext.TaskManage.init();
			
			//alert(newCallStatus);
            
            var img = document.getElementById('shortcut_agentStatus');
            //img.statusId = '4028dae619bd12950119bd355bc40005';
			
			
			if(newStatusId==img.statusId){
				return;
			}
			
/*
			//改变之前的状态
			var callStatus = img.callStatus;
			//如果是acw，特殊处理
            if (callStatus == '20005') {
                //alert(Ext.CaseManage);
                //如果工单没有保存
                if (!WORKERRECORD_GLOBAL_ISAVEDATA) {
                    Grandsys.sys.Utils.alertWarn('当前工单没有保存,请先保存!');
                    return false;
                }
                
                //alert('line:::671'+'到这里说明return挂了,没拦住!');
                
                Ext.CaseManage.stopCase('inLine_acw');
                //外呼ac
            }
            else if (callStatus == '20015') {
                //如果ACW状态被锁定，则不能成功转换
                if (!ACW_ENDABLE) {
                    Grandsys.sys.Utils.alertWarn(i18n.ShortcutSet.VAR_CUT_OWER_CURRENT);
                    return false
                }
                Ext.CaseManage.stopCase('inLine_acw');
            }
			
            
            //如果是就绪状态,清空一些东西
            if (newCallStatus == '10002') {
            
                onAvaiable();
                
            }
*/
			
			//获取即将改变的状态当前时间内是否可操作
			var info = getStatusInfo(newStatusId,img.statusId,'change');
			
			//如果是预览状态，最小化状态
			if(newCallStatus=='preview'){
				//alert('preview');
				//MiniWindow();
				//refreshIframe();
			}
			
            //改变状态之前的操作
            beforeChange(img.statusId);
            var oldStatusId = img.statusId;
            //完成改变状态
            img.src = newSrc;
            img.alt = newName;
            img.statusId = newStatusId;
			//表示交换机状态
    		img.callStatus = newCallStatus;
            //将改变后的状态保存到session
            //'Y'表示是手动切换的状态
            doChange(newStatusId, oldStatusId, 'N');
            
            //改变状态之后的操作
            afterChange(img);
			

            
			ApPlatform.statusChange(info.data);
			
			//开始执行最大时间任务
			//alert(info.endTime+":"+newAlertTime);
			Ext.TaskManage.init();
			//info.endTime,reds[0].get('alertTime')
			var startTime = info.startTime;
			logDebug('开始执行计时的时间:'+startTime);
			if (startTime != null) {
				logDebug("执行计时任务的时间:" + Date.parseDate(startTime, 'U').format('H:i:s'));
				Ext.TaskManage.delayTask(startTime, info.endTime, newAlertTime);
			}
			else if (info.endTime != null) {
				Ext.TaskManage.startDuration(info.endTime, newAlertTime);
			}
			else if (info.endTime == null) {
				try {
					Ext.TaskManage.stopDuration();
				} 
				catch (e) {
				
				}
			}
			else if (startTime == null) {
				try {
					Ext.TaskManage.stopDelayTask();
				} 
				catch (e) {
				
				}
			}
/*
            ApPlatform.statusChange(info.data);
            
            //开始执行最大时间任务
            //alert(info.endTime);
            Ext.TaskManage.init();
            //info.endTime,reds[0].get('alertTime')
            var startTime = info.startTime;
            logDebug('开始执行计时的时间:' + startTime);
            if (startTime != null) {
                logDebug("执行计时任务的时间:" + Date.parseDate(startTime, 'U').format('H:i:s'));
                Ext.TaskManage.delayTask(startTime, info.endTime, newstatus.alertTime);
            }
            else 
                if (info.endTime != null) {
                    Ext.TaskManage.startDuration(info.endTime, newstatus.alertTime);
                }
*/
			
/*
            //获取即将改变的状态当前时间内是否可操作
            var info = getStatusInfo(newStatusId, img.statusId, 'change');
            
            if (!info.isAllow) {
                //Ext.Msg.alert(ALERT_WIN_TITLE,'该状态目前不允许设置,请选择其他状态');
                Grandsys.sys.Utils.alertWarn('该状态目前不允许设置,请选择其他状态!');
            }
            else 
                if (info.isMax) {
                    //Ext.Msg.alert(ALERT_WIN_TITLE,'该状态已达到最大人数限制,请选择其他状态');
                    Grandsys.sys.Utils.alertWarn('该状态已达到最大人数限制,请选择其他状态！');
                }
                else 
                    if (info.data.isNotFinish) {
                        //Ext.Msg.alert(ALERT_WIN_TITLE,'业务模组没有做完,不能改变状态');
                        Grandsys.sys.Utils.alertWarn('上一状态业务模组没有做完,不能改变状态');
                    }
                    else {
                        //改变状态之前的操作
                        beforeChange(img.statusId);
                        var oldStatusId = img.statusId;
                        //完成改变状态
                        img.src = newSrc;
                        img.alt = newName;
                        img.statusId = newStatusId;
                        //将改变后的状态保存到session
                        //'Y'表示是手动切换的状态
                        doChange(newStatusId, oldStatusId, 'Y');
                        
                        //改变状态之后的操作
                        afterChange(img.statusId);
                        
                        ApPlatform.statusChange(info.data);
                        
                        //开始执行最大时间任务
                        //alert(info.endTime);
                        Ext.TaskManage.init();
                        //info.endTime,reds[0].get('alertTime')
                        var startTime = info.startTime;
                        logDebug('开始执行计时的时间:' + startTime);
                        if (startTime != null) {
                            logDebug("执行计时任务的时间:" + Date.parseDate(startTime, 'U').format('H:i:s'));
                            Ext.TaskManage.delayTask(startTime, info.endTime, newstatus.alertTime);
                        }
                        else 
                            if (info.endTime != null) {
                                Ext.TaskManage.startDuration(info.endTime, newstatus.alertTime);
                            }
                    }
*/
            
            /**
             * 前台任务操作区
             * 改变状态后开始执行最大时间任务
             */
/*
            if (info.endTime != null) {
                var endTime = info.endTime / 1000 //单位秒
            }
*/
            
            
            //win.close();
        }
    }
}
();

/**

快捷方式图标选择调用

**/

//id:'imgsel_bar'显示的toolbar

function showToolbar(){
	//alert('123');
	var toolbar = new Ext.Toolbar({
		id:'imgsel_toolbar'
//		,width:280
		,height:30
		,renderTo:'imgsel_bar'
	});

	btn_upload = new Ext.Button({
		text:i18n.ShortcutSet.VAR_CUT_UPLOAD_PIC
		,iconCls:'upload_icon'
		,tooltip:i18n.ShortcutSet.VAR_CUT_UPLOAD_MINEPIC
		,handler:function(){
			uploadfile.document.uploadForm.upload.click();
		}
	});

	btn_delete = new Ext.Button({
		text:i18n.common_Utils.DELETEBTNTEXT
		,iconCls:'remove'
		,tooltip:i18n.ShortcutSet.VAR_CUT_DEL_MINE_PIC
		,handler:function(){
			//Ext.MessageBox.alert('提示信息', '图片删除成功');
			Grandsys.sys.Utils.alertDropSuccess();
		}
	});

	toolbar.add(btn_upload,'-',btn_delete);
}


//上传开始进行的操作

function startUpload(){
	//Ext.MessageBox.alert('提示信息', '1图片上传成功');
	Grandsys.sys.Utils.alertInfo(i18n.ShortcutSet.VAR_CUT_UPLOAD_SUCC);
}

//快捷方式设定时的选择图片


function selectit(imgsrc){
	var src = '<img src="'+imgsrc+'" />'
	var setRecord=LinkageSettingGridSm.getSelections();
	var fourth_Data=LinkageSettingCm.getDataIndex(3);
	setRecord[0].set(fourth_Data,src);

}

//状态设定时的选择图片


function selectit_status(imgsrc){

	var src = '<img src="'+imgsrc+'" />'
	var setRecord=status_set_sm.getSelections();
	
	var fourth_Data=status_set_cm.getDataIndex(4);
	setRecord[0].set(fourth_Data,src);
	
}
//电话状态的设定图片
function setPic(imgsrc){
	alert(111);
	var src = '<img src="'+imgsrc+'" />'
	var setRecord=chebox.getSelections();
	//alert(setRecord);
	var pic_dataIndex=PhoneColumn.getDataIndex(3);
	setRecord[0].set(pic_dataIndex,src);
}

/*按钮弹出工作台栏目选择界面*/

/*function show_workplant(){


		var formpanel = new Ext.form.FormPanel({
				labelWidth:20,
				border:false,
				bodyStyle:'padding-top:8px;',
				defaultType:'checkbox',
				defaults:{labelSeparator:''},
				items:[{
					name:'swp_sel'
					,id:'swp_softphone'
					,checked:eastTab.getItem('msn')==null?false:true
					,boxLabel:'软电话'
				},{
					name:'swp_sel'
					,id:'swp_custominfo'
					,checked:eastTab.getItem('custInfoPanel')==null?false:true
					,boxLabel:'客户信息'
				},{
					name:'swp_sel'
					,id:'swp_history'
					,checked:eastTab.getItem('historyRecords')==null?false:true
					,boxLabel:'历史记录'
				},{
					name:'swp_sel'
					,id:'swp_wait'
					,checked:eastTab.getItem('pProceedingPanel')==null?false:true
					,boxLabel:'待办事项'
				},{
					name:'swp_sel'
					,id:'swp_connect'
					,checked:eastTab.getItem('msnPanel')==null?false:true
					,boxLabel:'联系人'
				}]
		});

		var panel = new Ext.Panel({
			layout:'accordion'
			,bodyStyle:'margin-bottom:-1px;'
			,layoutConfig: {
				titleCollapse: true,
				animate: true,
				activeOnTop: true
			}
			,items:[{
				title:'工作台'
				,border:false
				,items:formpanel
			},{
				title:'模组导航'
				,border:false
				,html:'11111'
			}]
		});

//    给window增加tbar


		var	win = new Ext.Window({
				layout: 'fit'
				,id:'workplant_window'
				,draggable:false
				,height: 350
				,width: 200
				,modal: true
				,resizable: false
				,closeAction: 'close'
				,autoScroll:true 
				,animateTarget: 'shortcut_workplant'
				,title: '窗口配置'
				,bodyStyle:'padding:5px;'
				,items: panel
				,tbar:[{
					text:i18n.common_Utils.SAVETEXT
					,iconCls:'save'
					,tooltip:'保存设定'
					,handler:function(){
						var sp_value = Ext.getCmp('swp_softphone').getValue();
						var ci_value = Ext.getCmp('swp_custominfo').getValue();
						var hi_value = Ext.getCmp('swp_history').getValue();
						var wi_value = Ext.getCmp('swp_wait').getValue();
						var co_value = Ext.getCmp('swp_connect').getValue();
						
						if(sp_value){
							addworkPanel(1);
						}else{
							eastTab.remove('msn');
						}
						if(ci_value){
							addworkPanel(2);
						}else{
							eastTab.remove('custInfoPanel');
						}
						if(hi_value){
							addworkPanel(3);
						}else{
							eastTab.remove('historyRecords');
						}
						if(wi_value){
							addworkPanel(0);
						}else{
							eastTab.remove('pProceedingPanel');
						}
						if(co_value){
							//alert(co_value);
							Ext.Messenger.load();
						}else{
							eastTab.remove('msnPanel',true);
						}						
					}
				},'-',{
					text:i18n.common_Utils.CANELTEXT
					,iconCls:'remove'
					,tooltip:'取消设定'		
					,handler:function(){
						
						win.close();
					}
				}]
		});

	var target = Ext.get('shortcut_workplant');

	win.on('render',function(){

		win.setPosition(target.getX()-180,target.getY()-360);
	
	});

	win.show();

	win.on('close',function(){
		//alert('closed');
	});
}*/


/* 主题/语言 -- 选择窗口*/

function show_theme(){

	var	winlan = new Ext.Window({
				layout: 'fit'
				,id:'theme_window'
				,draggable:false
				,height: 250
				,width: 150
				,modal: true
				,resizable: false
				,closeAction: 'close'
				,autoScroll:true 
				,animateTarget: 'shortcut_theme'
				,title: i18n.ShortcutSet.VAR_CUT_LANGUAGE_SET
				,bodyStyle:'padding:5px;'
				//,bodyStyle:'padding:8px;border-bottom:1px solid #99bbe8;',
				,autoLoad:{url:'theme.jsp',scripts:true}
				//,contentEl:'show_theme_win'
				//,items: panel
	});


	var target = Ext.get('shortcut_theme');

	winlan.on('render',function(){

		winlan.setPosition(target.getX()-100,target.getY()-250);
	
	});

	winlan.show();

	winlan.on('close',function(){
		//alert('closed');
	});
}

/*
*修改语言设置
*/
function do_theme(val){
	if(val == ''){
		return false;
	}
	Ext.Msg.confirm(ALERT_WIN_TITLE, i18n.ShortcutSet.VAR_CUT_LANGUAGE_COMFIRM, function(btn){	
	    if (btn == 'yes'){ 
	    	Ext.Ajax.request({    		
                url: '../pages/sysUser/sysUser03/User!saveI18nType.action?i18nType='+val,
                success : function(result, obj) {
						Grandsys.sys.Utils.alertSaveSuccess();
				},
				failure : function(result, obj) {
						Grandsys.sys.Utils.alertSaveFailure();
				}
            });
	    };
        Ext.getCmp('theme_window').close();
	});
	

}

/*
*改变快捷方式上的状态图片
*/
		function ChangPic(){
			var statusAlt=document.gear.alt;
			
			show_phoneWin();

		}
		
		/**
		 * 统一设定各种任务
		 */
        Ext.TaskManage = function(){
            var runner = new Ext.util.TaskRunner();
            //闪烁任务
            var taskBlink = {
                run: function(val){
					logDebug('我正在闪烁,帅吧');
                    var el = Ext.get('shortcut_agentStatus');
                    var img = document.getElementById('shortcut_agentStatus');
                    //img.alt = '该状态即将过期';
                    if (val % 2 == 0) {
                        //el.replaceClass('statusBlinkWhite', 'statusBlinkRed');
						el.setDisplayed(true);
                    }
                    else {
						el.setDisplayed(false);
						//el.hide();
                        //el.replaceClass('statusBlinkRed', 'statusBlinkWhite');
                    }
                },
                //duration:30000,
                interval: 500 //1 second
            };
			

            //计算状态持续时间任务
            var taskTime = {
                run: function(endTime,alertTime){
					var mydate = new Date().format('H:i:s');
					
					var alertDate = endTime-alertTime;
					
					var el = Ext.get('shortcut_agentStatus');

					logDebug('结束时间:'+Date.parseDate(endTime+'','U').format('H:i:s')+',当前时间:'+mydate);
					logDebug('告警时间:'+Date.parseDate(alertDate+'','U').format('H:i:s'));

					if(alertDate<endTime){
                        if (mydate == Date.parseDate(alertDate+'','U').format('H:i:s')) {
							logDebug('到时间执行闪烁的任务了');
							//el.setVisible(true,true);
                            //runner.stop(taskBlink);
                            runner.start(taskBlink);
                        }
					}
					
                    if (mydate == Date.parseDate(endTime + '', 'U').format('H:i:s')) {
                        logDebug('我不想闪了,累死了');
                        Ext.TaskManage.stopBlink();
						setTimeout('autoChangeStatus()',1000);
                        //setTimeout();
                        //el.removeClass(['statusBlinkWhite','statusBlinkRed']);
						
                        //autoChangeStatus();
                        //el.setDisplayed(true);
                    }

                },
                interval: 1000
            }
			
			//延时执行计算最大时间任务
            var delayTask = {
                run: function(startTime,endTime,alertTime){
					
					var mydate = new Date().format('H:i:s');
					logDebug('开始执行时间:'+Date.parseDate(startTime + '', 'U').format('H:i:s')+'\n现在时间:'+
					mydate);
					
                    if (mydate == Date.parseDate(startTime + '', 'U').format('H:i:s')) {
                        logDebug('时间到了,要开始计算这个状态的持续时间了');
                        Ext.TaskManage.startDuration(endTime,alertTime);
                    }

                },
                interval: 1000
            }
			
			
            return {
                init: function(){
                    try {
						
                        //删除已有样式
                        var el = Ext.get('shortcut_agentStatus');
                        if (el != null) {
							el.setDisplayed(true);
							el.repaint()
                            //el.removeClass(['statusBlinkWhite', 'statusBlinkRed']);
                        }
						//关闭所有执行中的任务
                        runner.stopAll();
                    } 
                    catch (e) {
                    	alert(e);
                    }
/*
					runner.stop(delayTask);
					runner.stop(taskTime);
					runner.stop(taskBlink);
*/
                },
				/**
				 * 开始持续时间任务
				 */
                startDuration: function(endTime,alertTime){
					
					var args = [endTime,alertTime];
					taskTime.args = args;
					//taskTime.duration = endTime;
                    runner.start(taskTime);
                },
				stopDuration:function(){
					runner.stop(taskTime);
				},
				stopBlink:function(){
					var el = Ext.get('shortcut_agentStatus');
					el.removeClass(['statusBlinkWhite','statusBlinkRed']);
					runner.stop(taskBlink);
				},
				delayTask:function(startTime,endTime,alertTime){    //延迟开始计时任务
					var args = [startTime,endTime,alertTime];
					delayTask.args = args;
					runner.start(delayTask);
				},
				stopDelayTask:function(){
					runner.stop(delayTask);
				}
            }
        }
        ();
		
		//Ext.TaskManage.init();
		
/*
		var timer=0;
		
		//状态改变后开始计时并在相应的时间执行闪烁任务
        function afterChange(record){
			
            Ext.Ajax.request({
                url: 'foo.php',
                success: function(result, obj){
                    var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                    if (jsonFromServer.success) {
						jsonFromServer.endTime
                        
                    }
                    else {
                        //Ext.MessageBox.alert("保存失败",jsonFromServer.msg);
                    }
                },
                failure: function(){
                
                },
                headers: {
                    'my-header': 'foo'
                },
                params: {
                    statusId: record.get('statusId')
                }
            });

			timer = 0;
			runner.start(taskTime);
        }
*/
		
		
	/**
	 * 手动改变状态操作
	 */
	function changeStatus(newStatus){
		
		//alert(newStatus.newAlertTime);
		
		//alert(2222);
		
		//var reds = dv.getSelectedRecords();
		var newSrc = newStatus.newSrc;
		var newName = newStatus.newName;
		var newStatusId = newStatus.newStatusId;
		//告警时间
		var newAlertTime = newStatus.newAlertTime;
		
		var newCallStatus = newStatus.newCallStatus;
		
		//alert('newSrc:'+newSrc+",newName:"+newName+",newStatusId:"+newStatusId+",newCallStatus:"+newCallStatus);
		var img = document.getElementById('shortcut_agentStatus');
		//img.statusId = '4028dae619bd12950119bd355bc40005';
		
        /*****************事后处理状态改变前的判断************************/

		//alert(img.callStatus);
		//如果是事后处理状态结束则需要调一个方法
	
		//改变之前的状态
		var callStatus = img.callStatus;
		//如果切换前是acw状态
		//进线acw
		/**
		if(callStatus=='20011'){
			//alert(Ext.CaseManage);
			//如果工单没有保存
			if(!WORKERRECORD_GLOBAL_ISAVEDATA){
				Grandsys.sys.Utils.alertWarn('当前工单没有保存,请先保存!');
				return false;
			}
			
			//alert('line:::671'+'到这里说明return挂了,没拦住!');
			
			Ext.CaseManage.stopCase('inLine_acw');
		//外呼ac
		}else if(callStatus == '20015'){

			//如果ACW状态被锁定，则不能成功转换
			if(!ACW_ENDABLE){
				Grandsys.sys.Utils.alertWarn(i18n.ShortcutSet.VAR_CUT_OWER_CURRENT); 
				return false
			}

			Ext.CaseManage.stopCase('inLine_acw');
		}
		*/
		
		/*****************事后处理状态改变前的判断************************/
		

		//如果是就绪状态,清空一些东西
        if (newCallStatus == '10002') {
			onAvaiable();
        }
		
		//获取即将改变的状态当前时间内是否可操作
		var info = getStatusInfo(newStatusId,img.statusId,'change');
		
		if(!info.isAllow){
			//Ext.Msg.alert(ALERT_WIN_TITLE,'该状态目前不允许设置,请选择其他状态');
			Grandsys.sys.Utils.alertWarn(i18n.ShortcutSet.VAR_CUT_CANT_SETSTATUS); 
		}else if(info.isMax){
			//Ext.Msg.alert(ALERT_WIN_TITLE,'该状态已达到最大人数限制,请选择其他状态');
			Grandsys.sys.Utils.alertWarn(i18n.ShortcutSet.VAR_CUT_THIS_STATUS);
		}else if(info.data.isNotFinish){
			//Ext.Msg.alert(ALERT_WIN_TITLE,'业务模组没有做完,不能改变状态');
			Grandsys.sys.Utils.alertWarn(i18n.ShortcutSet.VAR_CUT_NOT_OWER);
		}else{
			//改变状态之前的操作
			beforeChange(img.statusId);
			var oldStatusId = img.statusId;
			//完成改变状态
			img.src = newSrc;
			img.alt = newName;
			img.statusId = newStatusId;
			img.callStatus = newCallStatus;
			
            var el = Ext.get('shortcut_agentStatus');
            if (el != null) {
                el.setDisplayed(true);
                el.repaint()
                //el.removeClass(['statusBlinkWhite', 'statusBlinkRed']);
            }
			//将改变后的状态保存到session
			//'Y'表示是手动切换的状态
			doChange(newStatusId,oldStatusId,'Y');
			
			//改变状态之后的操作
			afterChange(img);
			
			ApPlatform.statusChange(info.data);
			
			//开始执行最大时间任务
			//alert(info.endTime);
			Ext.TaskManage.init();
			//info.endTime,reds[0].get('alertTime')
			var startTime = info.startTime;
			logDebug('开始执行计时的时间:'+startTime);
			if (startTime != null) {
				logDebug("执行计时任务的时间:" + Date.parseDate(startTime, 'U').format('H:i:s'));
				Ext.TaskManage.delayTask(startTime, info.endTime, newAlertTime);
			}
			else if (info.endTime != null) {
				Ext.TaskManage.startDuration(info.endTime, newAlertTime);
			}
			else if (info.endTime == null) {
				try {
					Ext.TaskManage.stopDuration();
				} 
				catch (e) {
				
				}
			}
			else if (startTime == null) {
				try {
					Ext.TaskManage.stopDelayTask();
				} 
				catch (e) {
				
				}
			}
		}
		
		/**
		 * 前台任务操作区
		 * 改变状态后开始执行最大时间任务
		 */
		if(info.endTime!=null){
			var endTime = info.endTime/1000   //单位秒
		}
		
		return true;
		
/*
		if (statusWin == null) {
			win.close();
		}
*/
		

	}

/**
*Agent状态的弹出窗口
*/
function show_phoneWin(){
	
    //建一个store
    var store = new Ext.data.JsonStore({
        //url: 'sysMeterial/sysMeterial05/agentstatus!getAllStatus.action',
		url:'statusManager/statusMgr!getAllStatusByPattern.action', //得到当前用户工作模式下的状态
        root: 'data',
        fields: [{name:'name',mapping:'statusName'}, {name:'url',mapping:'statusImage'},'alertTime','statusId','exchangeStatusName']
    });


	//建一个模板
	var tpl = new Ext.XTemplate(
		'<table width="100%" height="100%" class="statusTable" cellspacing="0" cellpadding="0">',
		'<tpl for=".">',
            '<tr class="statusShow">',
		    '<td align="center"><img height="16" width="16" src="{url}" title="{name}"></td>',
			'<td align="left">{name}</td>',
		    '</tr>',
        '</tpl>',
        '</table>'
	);
	
	var win;
	
	var statusWin = Ext.getCmp('agentstatus_window');
    
    if (statusWin == null) {
		
		
		store.load({
		callback:function(r){
			/*****控制状态弹出框显示位置***/
			var target = Ext.get('shortcut_agentStatus');
			var window = Ext.getCmp('agentstatus_window');
			var dataview = Ext.getCmp('status_dataview');
			var dvHeight;
			var height;
			if(dataview!=null){
				dvHeight = dataview.getSize().height;
			}
			
            //alert('dvHeight::'+dvHeight);
			if(window!=null){
				height = window.getFrameHeight() + dvHeight;
				window.setPosition(target.getX(), target.getY() - height-10);
			}
            
            //alert('height' + height);
            
			
			//alert(r.length);
			//window.setPosition(100, 200);
		}
	});
		
        win = new Ext.Window({
            layout: 'fit',
            id: 'agentstatus_window',
            draggable: false,
			shadow:false,
            height: 'auto',
            width: 108        //,modal: true
            ,
            resizable: false,
            closeAction: 'hide',
            autoScroll: true,
            //animateTarget: 'shortcut_phone',
            title: 'Agent'+i18n.ShortcutSet.VAR_CUT_STATUS,
            bodyStyle: 'padding:5px;width: 120px;'        /*
             ,tbar:[{
             text:'确认',
             handler:function(){
             var dv = Ext.getCmp('status_dataview');
             if(dv.getSelectionCount()==0){
             Ext.Msg.alert('', '请选择一个状态');
             }else{
             var reds = dv.getSelectedRecords();
             var img = document.getElementById('shortcut_agentStatus');
             img.src = reds[0].get('url');
             img.alt = reds[0].get('name');
             win.close();
             }
             }
             },{
             text:i18n.common_Utils.CANELTEXT,
             handler:function(){
             win.close();
             }
             }]
             */
            ,
            items: new Ext.DataView({
                store: store,
                tpl: tpl,
                id: 'status_dataview',
                autoHeight: true,
                width: 120,
                multiSelect: true,
                overClass: 'statusOver',
                selectedClass: 'statusSelected',
                itemSelector: '.statusShow',
                emptyText: i18n.ShortcutSet.VAR_CUT_STATUS_LOADING,
                prepareData: function(data){
                    //data.shortName = Ext.util.Format.ellipsis(data.name, 15);
                    //data.sizeString = Ext.util.Format.fileSize(data.size);
                    //data.dateString = data.lastmod.format("m/d/Y g:i a");
                    return data;
                }
            })
        });
    }

	//双击直接选择当前状态
	var dv = Ext.getCmp('status_dataview');
	
	dv.on('dblclick',changeStatus);
	

	
	
	var target = Ext.get('shortcut_agentStatus');
	
    
    if (statusWin == null) {
        win.on('render', function(){
        
            win.setPosition(target.getX(), target.getY());
            
        });
        
        
        win.show();
		
		win.on('close',function(){
			//delete win;
			//alert('closed');
		});
    }else{
		
		
		
		var target = Ext.get('shortcut_agentStatus');
			var window = Ext.getCmp('agentstatus_window');
			var dataview = Ext.getCmp('status_dataview');
			var dvHeight;
			var height;
			if(dataview!=null){
				dvHeight = dataview.getSize().height;
			}
			
            //alert('dvHeight::'+dvHeight);
			if(window!=null){
				height = window.getFrameHeight() + dvHeight;
				window.setPosition(target.getX(), target.getY() - height-10);
			}
			statusWin.show();
		 //statusWin.setPosition(target.getX(), target.getY());
	}
	
}


	/**
	 * 系统自动改变状态
	 */
    function autoChangeStatus(){
		
		var img = document.getElementById('shortcut_agentStatus');
		
		var nextStatus = getNextStatus(img.statusId);
		
		var el = Ext.get('shortcut_agentStatus');
		
		el.setDisplayed(true);
		
		el.repaint();
		
        if (nextStatus == null) {
        	logDebug('持续时间到了,但没有下个状态,保持当前状态不变');
            try {
                //Ext.TaskManage.init();
				Ext.TaskManage.stopDuration();
				el.setDisplayed(true);
				el.repaint();
            } 
            catch (e) {
            
            }
        }
        else {
            
			var newSrc = nextStatus.statusImage;
			var newName = nextStatus.statusName;
			var newStatusId = nextStatus.statusId;
			var newCallStatus = nextStatus.exchangeStatusName;
			
            //如果是就绪状态,清空一些东西
            if (newCallStatus == '10002') {
                onAvaiable();
            }
			
			var info = getStatusInfo(newStatusId,img.statusId,'change');
			
			if(info.data.isNotFinish){
				//Ext.Msg.alert(ALERT_WIN_TITLE,'业务模组没有做完,不能改变状态');
				Grandsys.sys.Utils.alertWarn(i18n.ShortcutSet.VAR_CUT_NOT_OWER);
                try {
                	Ext.TaskManage.init();
                } 
                catch (e) {
                
                }
				return;
			}
			
			var oldStatusId = img.statusId
            //改变状态之前的操作
            beforeChange(oldStatusId);
            
            //完成改变状态
            img.src = newSrc;
            img.alt = newName;
            img.statusId = newStatusId;
			img.callStatus = newCallStatus;
			
			var el = Ext.get('shortcut_agentStatus');
			
            if (el != null) {
				//alert(el.isDisplayed());
                el.setDisplayed(true);
                el.repaint()
                //el.removeClass(['statusBlinkWhite', 'statusBlinkRed']);
            }
			
            //将改变后的状态保存到session
			//'N'表示不是手动切换
            doChange(newStatusId,oldStatusId,'N');
/*
			try{
				Ext.TaskManage.init();
			}catch(e){
				
			}
*/
            
            //改变状态之后的操作
            afterChange(img);
			
			
            //调用方法设置交换机状态
            Ext.SoftPhoneAction.setAllStatus(newCallStatus);
			
			ApPlatform.statusChange(info.data);
            
            //开始执行最大时间任务
            //alert(info.endTime);
            
            //info.endTime,reds[0].get('alertTime')
            var startTime = info.startTime;
            logDebug('开始执行计时的时间:' + startTime);
            if (startTime != null) {
                logDebug("执行计时任务的时间:" + Date.parseDate(startTime, 'U').format('H:i:s'));
                Ext.TaskManage.delayTask(startTime, info.endTime, nextStatus.alertTime);
            }
            else 
                if (info.endTime != null) {
                    Ext.TaskManage.startDuration(info.endTime, nextStatus.alertTime);
                }
			else if(info.endTime==null){
                try {
                    Ext.TaskManage.stopDuration();
                } 
                catch (e) {
                
                }
			}else if (startTime == null) {
				try {
					Ext.TaskManage.stopDelayTask();
				} 
				catch (e) {
				
				}
			}
			
        }

    }

	/**
	 * 切换状态之前操作
	 */
	function beforeChange(statusId){
		
		 Ext.Ajax.request({
                url: 'statusManager/statusMgr!removeStatusUser.action',
                success: function(result, obj){
                    var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                    if (jsonFromServer.success) {
						logDebug("将用户从改变之前的状态中删除成功");
                    }
                    else {
                        logDebug("将用户从改变之前的状态中删除失败");
                    }
                },
                failure: function(){
                	logDebug("将用户从改变之前的状态中删除失败");
                },
                headers: {
                    'my-header': 'foo'
                },
                params: {
                    statusId: statusId
                }
            });
	}
	
	/**
	 * 切换状态的操作
	 */
	function doChange(statusId,oldStatusId,statusChangeType){
		
		 Ext.Ajax.request({
                url: 'statusManager/statusMgr!setStatus.action',
                success: function(result, obj){
                    var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                    if (jsonFromServer.success) {
						logDebug("成功将切换后的操作保存到Session");
                    }
                    else {
                        logDebug("将切换后的状态保存到Session失败");
                    }
                },
                failure: function(){
                	logDebug("将切换后的状态保存到Session失败");
                },
                headers: {
                    'my-header': 'foo'
                },
                params: {
                    statusId: statusId,
					oldStatusId:oldStatusId,
					statusChangeType:statusChangeType
                }
            });
			
	}
	
	/**
	 * 切换状态之后操作
	 */
    function afterChange(status){

		var callStatus = status.callStatus;
		
		//目前软电话状态,供工单保存的时候判断使用
		CURRENT_STATUS_CODE = callStatus;
		//alert('afterChange:::'+CURRENT_STATUS_CODE);
		//处理就绪按钮显示状态
        try {
			var avaliableBtn = Ext.getCmp('actAvaliable');
			var notAvaliableBtn = Ext.getCmp('Auxmu');
			var notAvaliablePausemuBtn = Ext.getCmp('Pausemu');
			
			//表示通话的过程中的状态
			var talkingStatus = ['20003','20004','20009',/*'20011','20012',*/'20000','20001','20002'];
			
			//通话中和服务中状态禁用就绪和未就绪按钮
			if(talkingStatus.indexOf(callStatus)!=-1){
				avaliableBtn.disable();
				notAvaliableBtn.disable();
				notAvaliablePausemuBtn.disable();
			}else{
				//非就绪状态时
				if(callStatus != '10002'){
					avaliableBtn.enable();
					notAvaliableBtn.disable();
					notAvaliablePausemuBtn.enable();
				}else{
					avaliableBtn.disable();
					notAvaliableBtn.enable();
					notAvaliablePausemuBtn.enable();
				}
				//notAvaliableBtn.enable();
				//notAvaliablePausemuBtn.enable();
			}

        } 
        catch (e) {
        
        }

		var el2 = document.getElementById('statuspath');
		if(el2!=null){
			el2.innerHTML = el2.innerHTML + '<br>callStatus:'+callStatus
		}
		//调用方法设置交换机状态
		//alert(callStatus);
		//Ext.SoftPhoneAction.setStatus(callStatus);

        Ext.Ajax.request({
            url: 'statusManager/statusMgr!setStatusUser.action',
            success: function(result, obj){
                var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                if (jsonFromServer.success) {
                    logDebug("将用户加入改变之后的状态中成功");
                }
                else {
                    logDebug("将用户加入改变之后的状态中失败");
                }
            },
            failure: function(){
                logDebug("将用户加入改变之后的状态中失败");
            },
            headers: {
                'my-header': 'foo'
            },
            params: {
                statusId: status.statusId
            }
        });
        
    }
	
	/**
	 * 用户退出或关闭浏览器初始化用户状态
	 */
    function initStatus(){
		
        Ext.TaskManage.init();
        var img = document.getElementById('shortcut_agentStatus');
        if (img != null) {
            var curStatus = img.statusId;
            Ext.Ajax.request({
                url: 'statusManager/statusMgr!initStatus.action',
                success: function(result, obj){
                    var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                    if (jsonFromServer.success) {
						//成功后返回登录页面
						setLoginOut();
						//alert(11);
                        logDebug("成功初始化用户状态");
                    }
                    else {
						setLoginOut();
						//alert(22);
                        logDebug("初始化用户状态失败");
                    }
                },
                failure: function(){
					setLoginOut();
					//alert(33);
                    logDebug("初始化用户状态失败");
                },
                headers: {
                    'my-header': 'foo'
                },
                params: {
                    statusId: curStatus
                }
            });
        }else{
			setLoginOut();
		}
        
    }
	
	/**
	 * 得到下个状态的相关信息
	 * @param {Object} statusId
	 * @param {Object} oldStatusId
	 */
	function getStatusInfo(statusId,oldStatusId,optType){
		
		var obj = null;
		var oldStatus = '';
		if(oldStatusId!=null){
			oldStatus = '&oldStatusId='+oldStatusId;
		}
		
		var optTypeStr = '&optType='+optType;
		
		//客户端时间(毫秒)
		var dt = new Date();
		var cTime = '&clientNowTime='+dt.getHours()+':'+dt.getMinutes()+':'+dt.getSeconds();
		
		//调用远程获取相关设置
		function getSet(statusId,oldStatusId){
            var conn = Ext.lib.Ajax.getConnectionObject().conn;
            conn.open("get", 'statusManager/statusMgr!getStatusSet.action?statusId='+statusId+optTypeStr+oldStatus+cTime, false);// false表示同步调用
            conn.send(null);
            
            var responseData = Ext.util.JSON.decode(conn.responseText);
			
            obj = {
				data:responseData,
                isAllow: responseData.isAllow,
                isMax: responseData.isMax,
                endTime: responseData.endTime,
				startTime:responseData.startTime
            }
		}
		
		getSet(statusId,oldStatusId);
		
		return obj;
	}
	
	/**
	 * 得到下个状态的信息
	 * @param {Object} statusId
	 */
    function getNextStatus(statusId){
    
        var status = null;
        
        //调用远程获取相关设置
        function getSet(statusId){
            var conn = Ext.lib.Ajax.getConnectionObject().conn;
            conn.open("get", 'statusManager/statusMgr!getNextStatus.action?statusId=' + statusId, false);// false表示同步调用
            conn.send(null);
            
            var responseData = Ext.util.JSON.decode(conn.responseText);
            
            if (responseData.data != null) {
                status = responseData.data;
            }
        }
        
        getSet(statusId);
        
        return status;
    }
/***
*点击电话状态的弹出窗口里面的图片
*修改快捷方式栏的显示图片状态
*/

	function setphonePic(imgsrc){
		var altDesc=document.gear.alt;
		var src = '<img src="'+imgsrc+'" />'
		var phone_window=Ext.getCmp('phone_window');
		if(altDesc==i18n.ShortcutSet.VAR_STATUSOK_PHONE_STATUS+'--Ready'){
				document.gear.src="images/icons/fam/user.gif";
				document.gear.alt=i18n.ShortcutSet.VAR_CUT_REST+"--Rest";
				phone_window.close();
			}if(altDesc==i18n.ShortcutSet.VAR_CUT_REST+"--Rest"){
				document.gear.src="images/icons/fam/user_red.png";
				document.gear.alt=i18n.ShortcutSet.VAR_STATUSOK_PHONE_STATUS+'--Ready';
				phone_window.close();
			}
	}
	
/**
 * 预约定时提醒任务
 */
	
//定时提醒预约到期任务

var alertrunner = new Ext.util.TaskRunner();


var bookingAlertTask = {
    run: function(){
		//alert(11);
        try {
            Ext.Ajax.request({
                url: 'common/BusSubscription!findBookingAlertRole.action',
                success: function(result, obj){
                    var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                    if (jsonFromServer.success) {
//                        var num = jsonFromServer.root; //所有的预约个数
//                        var isManager = jsonFromServer.isManager; //是否是管理员
//                        var managerSelf = jsonFromServer.managerSelf //管理员自己的预约个数
//                        var subCsr = jsonFromServer.subCsr //下属的名字和个数
                    	var inboundCount = jsonFromServer.inboundCount;
                    	var outboundCount = jsonFromServer.outboundCount;
                        var str = '';
                        if(inboundCount != 0) {
                        	str += i18n.common_Utils.VAR_BOOKING_ALERTING_YOU_HAVE + inboundCount + i18n.common_Utils.VAR_INBOUND_BOOKING;	//您今天有m個inbound的預約
                        }
                        if(outboundCount != 0) {
                        	if(str != '') {
                        		str += i18n.common_Utils.VAR_BOOKING_AND;	//和
                        	} else {
                        		str += i18n.common_Utils.VAR_BOOKING_ALERTING_YOU_HAVE;
                        	}
                        	str += outboundCount + i18n.common_Utils.VAR_OUTBOUND_BOOKING;
                        } else {
                        	if(str != "") {
                        		str += i18n.common_Utils.VAR_BOOKING_NOTDEAL;
                        	}
                        }
//                        //是管理员
//                        if (isManager) {
//                            if (num == null || num == 0) {
//                                return;
//                            }
//                            str += i18n.common_Utils.VAR_BOOKING_ALERTING_YOU_HAVE + num + i18n.common_Utils.VAR_BOOKING_ALERTING_JINKUAI+i18n.common_Utils.VAR_BOOKING_ALERTING_BAOHAN;
//                            if (managerSelf != null && managerSelf > 0) {
//                                str += i18n.common_Utils.VAR_BOOKING_ALERTING_MANAGER + managerSelf + i18n.common_Utils.VAR_BOOKING_ALERTING_GE;
//                            }
//                            if (subCsr.length > 0) {
//                                for (var i = 0; i < subCsr.length; i++) {
//                                    str += i18n.common_Utils.VAR_BOOKING_ALERTING_XIASHU + subCsr[i].csrName + i18n.common_Utils.VAR_BOOKING_ALERTING_HAVE + subCsr[i].subScriptionNum + i18n.common_Utils.VAR_BOOKING_ALERTING_GE;
//                                }
//                            }
//                            
//                        }
//                        else {
//                            if (num != null && num > 0) {
//                                str += i18n.common_Utils.VAR_BOOKING_ALERTING_YOU_HAVE + num + i18n.common_Utils.VAR_BOOKING_ALERTING_JINKUAI;
//                            }
//                        }
                        if (str.length > 0) {
                        	str += i18n.common_Utils.VAR_BOOKING_DEAL_PLEASE;
                            Ext.Msg.show({
                                title: '',
                                msg: str,
                                buttons: Ext.Msg.OK
                                //icon: Ext.MessageBox.WARNING
                            });
                        }
                    }
                    else {
                        //Grandsys.sys.Utils.alertError(i18n.ShortcutSet.VAR_CASE_BEGIN_ERROR);
                    }
                    
                },
                failure: function(result, obj){
                    //Grandsys.sys.Utils.alertSaveFailure();
                },
                headers: {
                    'my-header': 'foo'
                },
                params: {}
            });
        } 
        catch (e) {
        
        }

    },
    //interval:  60*1000
	interval:  60*60*1000
}		

//後臺服務已經停止提示任務
var taskRequestIsOK = {
    run: function(val){
    	try {
    	//请求一個後臺空方法
         Ext.Ajax.request({
             url: 'common/BusSubscription!checkServerRun.action',
             success: function(result, obj){
             },
             failure: function(result, obj){
                 alert(i18n.ShortcutSet.VAR_SERVERSTOP);//"後臺服務已經停止 "
                 alertrunner.stop(taskRequestIsOK);
             },
             headers: {
                 'my-header': 'foo'
             }
             })
     }catch(e){
     }
    },
    interval: 10000
};
	
	
/**
*安全退出
*/
function SafeOut(){
	
Ext.Msg.confirm(ALERT_WIN_TITLE,i18n.ShortcutSet.VAR_CUT_SAFE_OUT, function(btn, text){	
    if (btn == 'yes'){    	
    	 setLoginOut();
		 //initStatus();
    }
});
	
}


function setLoginOut(){

		//if(AIC_SYSTEM!=null&&AIC_SYSTEM == 'Aspect'){

            try {
                //如果用户已经登录软电话，则登出交换机
				//alert(Ext.SoftPhoneAll.isLogon());
                if (Ext.SoftPhoneAll.isLogon()) {
                	//登出交换机
                	Ext.SoftPhoneAll.logOutAgent();    
                }
                
                //关闭ocx进程
                //Ext.SoftPhoneAll.beforeUnload();
            } 
            catch (e) {
            
            }
		//}
		
		//初始化任务
		Ext.TaskManage.init();
		
		//结束预约提醒任务
		alertrunner.stopAll();
		
        var img = document.getElementById('shortcut_agentStatus');
		//初始化状态
        if (img != null) {
            var curStatus = img.statusId;
			
            var conn = Ext.lib.Ajax.getConnectionObject().conn;
            conn.open("get", 'statusManager/statusMgr!initStatus.action?statusId='+curStatus, false);// false表示同步调用
            conn.send(null);
        }
		LoginOut();

				
		//登出方法			
		function LoginOut(){
			var conn = Ext.lib.Ajax.getConnectionObject().conn;
            conn.open("get", 'login!loginOut.action?nodeId=abcd&parentId=cdef', false);// false表示同步调用
            conn.send(null);
			
			//window.location.replace('../');
			
			//登出后关闭IE
			setTimeout(function(){
				window.opener= null; 
				window.open("","_self"); 
				window.close();
			},1000)
/*
			Ext.Ajax.request({
                url: 'login!loginOut.action',
                success: function(result,obj){
					  javascript:window.location.replace('../');
                },
                failure: function(result,obj){
					  javascript:window.location.replace('../');
                },
                headers: {
                    'my-header': 'foo'
                },
                params: {
                    nodeId: 'abcd',
					parentId: 'cdef'
                }
            });
*/
		}
	
	}


function Switching(){//切换状态

	 var responseData;
  try { 
  	    var tdid=document.getElementById("tdid");
		var text=tdid.childNodes[0];  	
  	
		var conn = Ext.lib.Ajax.getConnectionObject().conn;
		conn.open("get", 'login!getTime.action', false);// false表示同步调用
		conn.send(null);
	    
	    //alert('responseText='+conn.responseText);
	    var fullText =conn.responseText;
	    var startIndex =fullText.indexOf('window.location');
	    //alert('startIndex='+startIndex);
	    if(startIndex >-1){
	    	//alert('--'+'abcdd'.substr(1));
	    	var str =fullText.substr(startIndex+24);
	    	//alert('first cut ='+str);
	    	var endIndex = str.indexOf('\";');
	    	//alert('-- --');
	    	var url=str.substring(0,endIndex);
	    	
	    	//Ext.Msg.alert('提示信息','系统用户已在别处登录,或会话过期,将返回登录界面.');
	    	Grandsys.sys.Utils.alertErrorn(i18n.ShortcutSet.VAR_CUT_SESSION_ONTIME);
	    	setTimeout(function(){ window.location.replace(url);},10*1000);
	    	return;
	    	
	    }
	    
	    responseData= Ext.util.JSON.decode(conn.responseText);
	   //alert('responseData='+responseData);
	   //alert('responseData.success ='+responseData.success);
	 
	 } catch(ex)//catch the ex 
    {   
    	//alert('处错误了！！');
    	//alert(ex.number+"\n"+ex.description+'--'+ex.ErrorMessage); 
		text.nodeValue=i18n.ShortcutSet.VAR_CUT_READ_HISERROR;
    	return;      
    } 
    finally 
    { 
       //...
    } 

		userName = responseData.userName;
		count =responseData.countTime;
//		alert(" userName ="+responseData.userName);
//		alert(" countTime ="+responseData.countTime);		
//		alert(" loginTime ="+responseData.loginTime);/		
		
		setTimeout('Switching()',10*60*1000); //20minite
		LoginTime=responseData.loginTime;		
		
		//setInterval(swit,3000);
		swit();
	}
	
	
/*
 * 主要实现左下角文字信息更新提示   kevin20081030修改之
 */
    function swit(){
		
		var tdid=document.getElementById("tdid");
		var text=tdid.childNodes[0];  
		
		var second_value=i18n.ShortcutSet.VAR_CUT_ON_TIME+':'+LoginTime;	
		var login_user =i18n.ShortcutSet.VAR_CUT_ON_PEPO+':'+userName;
		var count_time =i18n.ShortcutSet.VAR_CUT_TOTAL_TIME+count+i18n.ShortcutSet.VAR_CUT_HOUR;	
    
        if (text.nodeValue.indexOf(i18n.ShortcutSet.VAR_CUT_ON_PEPO) > -1) {
        
            text.nodeValue = second_value;
            
        }
        else if (text.nodeValue.indexOf(i18n.ShortcutSet.VAR_CUT_ON_TIME) > -1) {
        
//            text.nodeValue = count_time;
//        }
//        else if (text.nodeValue.indexOf(i18n.ShortcutSet.VAR_CUT_TOTAL_TIME) > -1) {
        
            text.nodeValue = login_user;
        }
        else {
            text.nodeValue = login_user;
        }
		
		setTimeout('swit()',3000); //3s
    }
	
//swit();

/*
*主要实现系统时间－－－－－暂时没有用到
**/
function showSystemTime(){
	today=new Date();
	document.write("<font color=#003344> ",today.getFullYear(),i18n.common_Utils.YEAR, today.getMonth()+1,i18n.common_Utils.MONTH,
				today.getDate(),i18n.common_Utils.DAY,today.getHours(),i18n.ShortcutSet.VAR_CUT_SHI,today.getMinutes(),i18n.ShortcutSet.VAR_CUT_FEN, 
				 "</font>" ); 
}


function showMsgBox(msg) {
		Ext.MessageBox.show( {
		msg : msg,
		buttons : Ext.MessageBox.OK,
		icon : Ext.MessageBox.WARNING
				});
			}
